package breeze.tool.life.database;
import breeze.tool.life.App;
import android.database.sqlite.SQLiteDatabase;
import android.content.ContentValues;
import java.util.List;
import brz.breeze.service_utils.BExceptionCatcher;
import android.database.Cursor;
import java.util.ArrayList;

public class AppSqlUtils {
    
    /*
	*@author BREEZE
	*@date 2021-11-20 21:54:08
    */
    public static final String TAG = "AppSqlUtils";
    
	private static AppSqliteOpenHelper helper;
	
	private static SQLiteDatabase database;
	
    static{
		helper = new AppSqliteOpenHelper(App.getContext(),"Express.db",null,1);
		database = helper.getWritableDatabase();
	}
	
	public static void addData(String express){
		//Name
		ContentValues cv = new ContentValues();
		cv.put("ExpressID",express);
		database.insert("express",null,cv);
	}
	
	public static List<String> getAllDatas(){
		try{
			List<String> datas = new ArrayList<>();
			Cursor cursor = database.query("express",null,null,null,null,null,null);
			if(cursor.moveToFirst()){
				do{
					String data = cursor.getString(cursor.getColumnIndex("ExpressID"));
					datas.add(data);
				}while(cursor.moveToNext());
				return datas;
			}
			return null;
		}catch(Exception e){
			BExceptionCatcher.e(App.getContext(),e);
			return null;
		}
	}
	
	public static void delete(String express){
		database.delete("express","ExpressID = ?",new String[]{express});
	}
    
}
